package ai.fabu.dataplatform.bean.framedata;

import ai.fabu.dataplatform.utils.TimeUtil;
import com.google.common.primitives.Longs;
import lombok.Setter;
import lombok.Value;
import lombok.experimental.NonFinal;
import org.bson.types.ObjectId;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.CompoundIndex;
import org.springframework.data.mongodb.core.index.CompoundIndexes;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;

import java.util.HashMap;
import java.util.Map;

import static ai.fabu.dataplatform.constant.ConstantName.*;

@Value
@Document(collection = "frame")
@CompoundIndexes({
        @CompoundIndex(def = "{'group_name':1, 'bag_name':1, 'topic_name':1, 'frame_no':1}", unique = true)
})
public class FrameData {
    public static FrameData staticFrameData(String groupName, String bagName, String topicName, Integer frameNo, String binPath){
        Map<String, byte[]> metadata = new HashMap<String, byte[]>(){
        {
                put(CREATE_TIME, TimeUtil.getNowTimestampLong().toString().getBytes());
                put(UPDATE_TIME, TimeUtil.getNowTimestampLong().toString().getBytes());
            }
        };
        return new FrameData(null, groupName, bagName, topicName, frameNo, binPath, metadata);
    }

    @Id
    @NonFinal
    @Setter
    ObjectId frameId;
    @Field(GROUP_NAME)
    String groupName;
    @Field(BAG_NAME)
    String bagName;
    @Field(TOPIC_NAME)
    String topicName;
    @Field(FRAME_NO)
    Integer frameNo;
    @Field(BIN_PATH)
    String binPath;
    Map<String, byte[]> metadata;
}
